package sample.plugin.html.project.running;

import com.rapid.api.Platform;
import com.rapid.api.component.widget.window.Window;
import com.rapid.api.ext.framework.BaseObject;
import com.rapid.api.framework.DataKeys;
import com.rapid.api.project.component.running.RunConfiguration;

import java.net.URI;

public class InnerBrowserRunConfig extends BaseObject implements RunConfiguration {

    @Override
    public String getId() {
        return "default-browser-run";
    }

    @Override
    public String getName() {
        return "内置浏览器";
    }

    @Override
    public void prepare(ReadyPresentation readyPresentation) {
        readyPresentation.ready(true);
    }

    @Override
    public void run(ResultPresentation resultPresentation) {
        Window window = Platform.getData(DataKeys.WINDOW);
        if (window != null) {
            URI uri = window.getVirtualFile().asURI();;
            openBrowser(uri.toString());
            resultPresentation.onSuccess();
        }
    }
}